1 00:00:00,290 --> 00:00:02,930 Now let's write some code to show the beam. 2 00:00:02,930 --> 00:00:04,040 So we have a player. 3 00:00:04,040 --> 00:00:05,030 They bought a lot. 4 00:00:05,060 --> 00:00:05,690 They left. 5 00:00:05,720 --> 00:00:06,890 They came back. 6 00:00:06,920 --> 00:00:12,560 We're going to have a beam light up for them to show them where they should go for their lot. 7 00:00:12,590 --> 00:00:18,800 We want the beam only to be visible to the player who owns the lot so that other people don't get confused. 8 00:00:18,800 --> 00:00:20,630 We don't want beams going everywhere. 9 00:00:20,630 --> 00:00:23,210 So this is going to be a client side thing. 10 00:00:23,210 --> 00:00:27,860 Let's go over to our property manager, take a look at that. 11 00:00:27,860 --> 00:00:34,130 And in the property manager, when we enter the game, we're going to have this equip player. 12 00:00:34,160 --> 00:00:40,280 Equip player is where we're going to send a remote event to the client to light up the beam. 13 00:00:40,280 --> 00:00:46,340 This has to be done client side so that only our player can see the beam, only they can see their beam. 14 00:00:46,520 --> 00:00:54,590 Let's make a beam remote event so that we could send messages from our property manager to our client. 15 00:00:54,590 --> 00:01:01,250 So I'm going to go to replicated storage, hit the plus, and then add a remote event and I'm going 16 00:01:01,250 --> 00:01:04,160 to call that Beam Ray. 17 00:01:05,330 --> 00:01:05,630 All right. 18 00:01:05,660 --> 00:01:12,260 Now, in order for us to fire off that remote event, let's go to the top of our property manager. 19 00:01:12,260 --> 00:01:20,150 If you don't remember where it's at, it's in our server script service, and I will get a variable 20 00:01:20,150 --> 00:01:29,600 for replicated storage game, get service, replicated storage, and then a variable for the beam ray. 21 00:01:29,930 --> 00:01:32,150 So it is in replicated storage. 22 00:01:32,150 --> 00:01:35,600 We'll do a wait for child beam ray. 23 00:01:35,870 --> 00:01:47,390 Now get that beam Ray, go back to our equip player and we're going to I'll just paste that beam ray 24 00:01:48,740 --> 00:01:51,410 fire client. 25 00:01:51,530 --> 00:01:53,570 We're going to need some arguments here. 26 00:01:53,570 --> 00:01:59,000 So the first thing I'm going to do is pass in the player that the remote event is going to because we're 27 00:01:59,000 --> 00:02:00,690 sending it to a player. 28 00:02:00,690 --> 00:02:03,570 And then I need the beam itself. 29 00:02:03,570 --> 00:02:12,960 We're going to activate it on, on client side V is a lot and on the lot we have the lot part right, 30 00:02:12,960 --> 00:02:15,210 the gray part, the part for the base. 31 00:02:15,210 --> 00:02:22,350 And then on the lot part we have the beam itself and I'm also going to send a flag. 32 00:02:22,500 --> 00:02:23,520 It's going to be true or false. 33 00:02:23,520 --> 00:02:25,020 I'm going to send it true now. 34 00:02:25,020 --> 00:02:27,060 And that's going to mean on or off. 35 00:02:27,060 --> 00:02:29,610 Do we turn the beam on or do we turn the beam off? 36 00:02:29,610 --> 00:02:30,630 When we touch it? 37 00:02:30,660 --> 00:02:32,400 We're going to turn the beam off. 38 00:02:33,390 --> 00:02:36,180 Now, where should we put the script for the client? 39 00:02:36,210 --> 00:02:39,750 Well, let's go down and look at Starter Player. 40 00:02:39,990 --> 00:02:44,880 Open that up and I'm going to put this in starter player scripts. 41 00:02:44,880 --> 00:02:47,120 So these are client side scripts. 42 00:02:47,130 --> 00:02:50,610 I'm going to hit that plus sign and add a local script. 43 00:02:51,600 --> 00:02:53,850 And then I'm going to call this. 44 00:02:54,770 --> 00:02:55,610 Oh, something easy. 45 00:02:55,610 --> 00:02:57,470 Like Beam script. 46 00:03:00,960 --> 00:03:03,420 I can make this a little bigger so you can see it. 47 00:03:05,880 --> 00:03:07,230 We're going to get replicated. 48 00:03:07,230 --> 00:03:08,790 Storage game. 49 00:03:08,790 --> 00:03:09,120 Get. 50 00:03:10,590 --> 00:03:12,690 Replicated storage. 51 00:03:12,810 --> 00:03:19,100 We are going to get the beam remote event or beam re replicated storage. 52 00:03:19,110 --> 00:03:21,450 Wait for child beam ra. 53 00:03:22,080 --> 00:03:33,750 The Beam re is going to look for the on client event and we'll put an anonymous function in here. 54 00:03:33,750 --> 00:03:38,880 Remember, we pass three arguments the player, the beam itself and then a boolean. 55 00:03:38,880 --> 00:03:43,710 Whether you're turning it on or off, on or off, we don't need the player because we already got to 56 00:03:43,710 --> 00:03:44,130 the player. 57 00:03:44,130 --> 00:03:45,450 So the player is gone. 58 00:03:45,450 --> 00:03:51,390 So the next argument on the list will be the beam itself and then the status, whether it's going to 59 00:03:51,390 --> 00:03:52,950 be true or false. 60 00:03:53,700 --> 00:04:02,250 I'm going to just do beam dot enabled equals status. 61 00:04:02,250 --> 00:04:05,740 And now we could use this script for turning it off too, right? 62 00:04:05,740 --> 00:04:10,660 We'll just put the status whether we want it on or whether we want it off now. 63 00:04:10,660 --> 00:04:12,580 We need to be able to turn the beam off. 64 00:04:12,580 --> 00:04:15,520 The property manager picked up the fact that we own a lot. 65 00:04:15,550 --> 00:04:16,930 We entered the game. 66 00:04:16,930 --> 00:04:20,770 It lit up the beam by sending a remote event to the Beam script. 67 00:04:20,770 --> 00:04:23,890 On the client side, Bam status was true. 68 00:04:23,920 --> 00:04:25,150 Beams lit up. 69 00:04:25,150 --> 00:04:31,120 When we get to the lot, touch the part, we're going to turn the beam off, perhaps use a time or two. 70 00:04:31,120 --> 00:04:34,510 So let's scroll up to our workspace. 71 00:04:34,510 --> 00:04:42,010 Open up that workspace, go to the lock collection, open up your player lot, and the bias script has 72 00:04:42,010 --> 00:04:42,850 all the code, right? 73 00:04:42,850 --> 00:04:47,350 So let's open up by script and I see a lot model. 74 00:04:47,350 --> 00:04:51,160 I don't see that gray part this lot right here. 75 00:04:51,190 --> 00:04:53,260 That's what we need to step on. 76 00:04:53,260 --> 00:04:55,390 So let's get a variable for that. 77 00:04:55,540 --> 00:04:58,270 Let's say local lot. 78 00:04:59,170 --> 00:05:00,700 I'll just call that lot. 79 00:05:00,730 --> 00:05:02,230 That's the lot part there. 80 00:05:02,230 --> 00:05:02,710 Right? 81 00:05:02,710 --> 00:05:08,220 And then we're going to get the lot model lot part nice. 82 00:05:08,220 --> 00:05:18,060 Now let's scroll down here, we'll get the lot touch event, connect that to an anonymous function. 83 00:05:18,090 --> 00:05:23,460 Whatever touched the lot is going to be passed in here. 84 00:05:23,460 --> 00:05:26,800 We could just say other part, right? 85 00:05:26,940 --> 00:05:32,400 And I'm not interested in trees or anybody else walking on this thing. 86 00:05:32,400 --> 00:05:41,010 What I am interested in is if a player touched the part and if it's my player, more specifically the 87 00:05:41,010 --> 00:05:43,200 the lot owner player, right? 88 00:05:43,200 --> 00:05:48,210 So I'll say local player, I'm going to use the game service. 89 00:05:48,240 --> 00:05:50,130 Whoops, I'm going to need an equals sign. 90 00:05:50,130 --> 00:05:52,350 I'm going to use a game service. 91 00:05:52,350 --> 00:05:55,950 And then we got the player service Colon. 92 00:05:55,980 --> 00:05:58,890 There's this get player added from character. 93 00:05:59,210 --> 00:06:00,600 That's kind of crazy. 94 00:06:00,600 --> 00:06:01,710 That's all right though. 95 00:06:01,740 --> 00:06:05,950 We can get the other part and the parent. 96 00:06:07,570 --> 00:06:08,980 That's too big. 97 00:06:09,070 --> 00:06:09,490 You know what? 98 00:06:09,490 --> 00:06:10,480 Should we do this? 99 00:06:11,770 --> 00:06:13,710 Yeah, we'll just shrink that down a little bit. 100 00:06:13,720 --> 00:06:18,760 If the if the thing that touched the part is a foot or something like that, the parents are going to 101 00:06:18,760 --> 00:06:24,310 be the character, then we're going to have a character right here and then get player from character 102 00:06:24,310 --> 00:06:29,140 is going to be able to find the player associated with the character or not. 103 00:06:29,140 --> 00:06:32,260 But if it does, it's going to put that value in here. 104 00:06:32,260 --> 00:06:37,990 If it doesn't find the player associated with it, like if a zombie stepped on it, then it would just 105 00:06:37,990 --> 00:06:39,670 be nil, the player would be nil. 106 00:06:39,670 --> 00:06:46,750 So we'll say if player then well, that's a player, but we got to make sure it's our player, it's 107 00:06:46,750 --> 00:06:48,130 the lot owner player. 108 00:06:48,130 --> 00:06:58,060 So I'm going to say if player and player equals equals the owner, right? 109 00:06:58,210 --> 00:06:59,830 We have an owner. 110 00:07:01,520 --> 00:07:01,850 Oh, good. 111 00:07:01,850 --> 00:07:03,490 I was worried we didn't have an owner variable. 112 00:07:03,500 --> 00:07:04,280 We do though. 113 00:07:04,280 --> 00:07:08,150 We have an owner variable and the owner value is the player. 114 00:07:08,150 --> 00:07:09,350 So. 115 00:07:09,850 --> 00:07:13,330 Then what we can do is send a remote event. 116 00:07:13,420 --> 00:07:16,390 Oh, we need to get replicated storage and stuff like that. 117 00:07:16,390 --> 00:07:18,430 Or we could just do it right here, right? 118 00:07:18,460 --> 00:07:20,110 We might not need it anywhere else. 119 00:07:20,110 --> 00:07:27,940 So I'm going to say local replicated storage game, get service, replicated storage and we'll get a 120 00:07:27,970 --> 00:07:31,900 beam re from replicated storage. 121 00:07:31,930 --> 00:07:40,180 Wait for child beam ray to move that up and then our beam ray. 122 00:07:40,480 --> 00:07:42,490 I got to spell it a little better than that. 123 00:07:42,520 --> 00:07:44,590 We're going to do a fire client. 124 00:07:45,910 --> 00:07:48,100 We're going to pass in the player. 125 00:07:48,100 --> 00:07:52,180 And this time lot is simply lot. 126 00:07:52,630 --> 00:07:53,790 Oh, we need the beam, right? 127 00:07:53,800 --> 00:07:55,420 Not just a lot, but the beam. 128 00:07:55,450 --> 00:07:56,650 The beam. 129 00:07:56,860 --> 00:07:58,390 And then false is going to be. 130 00:07:58,390 --> 00:07:59,860 Hey, turn it off. 131 00:08:00,370 --> 00:08:02,020 All right, let's try this out. 132 00:08:02,620 --> 00:08:08,980 And we should try it with our test server, too, to see if the other player can't turn it off. 133 00:08:11,920 --> 00:08:13,060 There's our beam. 134 00:08:14,160 --> 00:08:15,660 Well, we should check. 135 00:08:18,650 --> 00:08:19,970 Make sure we don't have any errors. 136 00:08:20,000 --> 00:08:22,420 See how that beam is going the whole way, though. 137 00:08:22,430 --> 00:08:28,340 Some people attach the beam to the character itself and that way it disappears as they move forward. 138 00:08:28,340 --> 00:08:30,650 We might want to do that all. 139 00:08:30,650 --> 00:08:31,280 Look at that. 140 00:08:31,280 --> 00:08:32,810 The beam went off. 141 00:08:33,050 --> 00:08:34,250 That's pretty good.